home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d20 / pvert.arc / STRISTR.C < prev    next >
C/C++ Source or Header  |  1992-01-15  |  1KB  |  85 lines

  1. #include <stdlib.h>
  2.  
  3.  
  4. /* insensitive strstr() */
  5.  
  6. char * stristr (char *t, char *s) {
  7.  
  8.    char *t1;
  9.    char *s1;
  10.  
  11.  
  12.    while(*t) {
  13.       t1 = t;
  14.       s1 = s;
  15.       while(*s1) {
  16.          if (toupper(*s1) != toupper(*t)) break;
  17.          else {
  18.             s1++;
  19.             t++;
  20.          }
  21.       }
  22.       if (!*s1) return t1;
  23.       t = t1 + 1;
  24.    }
  25.    return NULL;
  26. }
  27.  
  28.  
  29.  
  30.  /* case insensitive strnstr() */
  31.  
  32. char * strnistr (char *t, char *s, size_t n) {
  33.  
  34.    char *t1;
  35.    char *s1;
  36.  
  37.  
  38.    while(*t) {
  39.        t1 = t;
  40.        s1 = s;
  41.        while(*s1) {
  42.            if (toupper(*s1) != toupper(*t)) break;
  43.            else {
  44.                n--;
  45.                s1++;
  46.                t++;
  47.                if(!n) break;
  48.            }
  49.        }
  50.        if (!*s1) return t1;
  51.        t = t1 + 1;
  52.    }
  53.    return NULL;
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  /* strnstr() */
  61.  
  62. char * strnstr (char *t, char *s, size_t n) {
  63.  
  64.    char *t1;
  65.    char *s1;
  66.  
  67.  
  68.    while(*t) {
  69.        t1 = t;
  70.        s1 = s;
  71.        while(*s1) {
  72.            if (*s1 != *t) break;
  73.            else {
  74.                n--;
  75.                s1++;
  76.                t++;
  77.                if(!n) break;
  78.            }
  79.        }
  80.        if (!*s1) return t1;
  81.        t = t1 + 1;
  82.    }
  83.    return NULL;
  84. }
  85.